home *** CD-ROM | disk | FTP | other *** search
/ MacHack 2000 / MacHack 2000.toast / pc / The Hacks / Genie / Projects / A-line / Scripts / SCF.pm < prev    next >
Encoding:
Perl POD Document  |  2000-06-24  |  772 b   |  47 lines

  1. package SCF;
  2.  
  3. require Exporter;
  4. @ISA = qw(Exporter);
  5. @EXPORT = qw(Read Sections Keys Lookup);
  6.  
  7. use strict;
  8.  
  9. sub Read {
  10.     local @ARGV = @_;
  11.     defined @ARGV or return undef;
  12.     my %DATA;
  13.     my $section = '';
  14.     while (<>) {
  15.         chop;
  16.         next if !length;
  17.         next if /^;/;
  18.         if (/^\[([-\w. ]+)\]$/) {
  19.             $section = $1;
  20.         } elsif (/^(\w+)\s*=\s*(.*)/) {
  21.             $DATA{$section}{$1} = $2;
  22.         }
  23.     }
  24.     return \%DATA;
  25. }
  26.  
  27. sub Sections {
  28.     my ($dataref) = @_;
  29.     return keys %$dataref;
  30. }
  31.  
  32. sub Keys {
  33.     my ($dataref, $section) = @_;
  34.     return keys %{$dataref->{$section}};
  35. }
  36.  
  37. sub Lookup {
  38.     my ($dataref, $section, $key) = @_;
  39.     return $dataref->{$section}{$key};
  40. }
  41.  
  42. sub Collect {
  43.     my ($dataref, $key) = @_;
  44.     return map { $_, $dataref->{$_}{$key} } 
  45.         grep { defined $dataref->{$_}{$key} } Sections($dataref);
  46. }
  47.